package controllers;

import beans.AftersalesLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import services.impl.AftersalesLogServicesImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/aftersale")
public class AftersalesLogController {

    @Autowired
    private AftersalesLogServicesImpl alsi;

    @RequestMapping("/aftersale")
    public List afterSale(){
        List<AftersalesLog> list = alsi.selectList();
        return list;
    }

    @RequestMapping("/createaftersale")
    public String createAfterSale(@RequestBody AftersalesLog aftersalesLog){
        alsi.insertSelective(aftersalesLog);
        return null;
    }
    @RequestMapping("/editaftersale_log")
    public String afterSaleLog(@RequestBody AftersalesLog aftersalesLog){
        alsi.updateByPrimaryKeySelective(aftersalesLog);
        return null;
    }
    @RequestMapping("/detailsaftersale")
    public AftersalesLog detailsAfterSale(HttpServletRequest request){
        int i = Integer.parseInt(request.getParameter("aftersalesId"));
        AftersalesLog aftersalesLog = alsi.selectByPrimaryKey(i);
        return aftersalesLog;
    }

    @RequestMapping("/searchaftersale")
    public List<AftersalesLog> searchAfterSale(@RequestBody Map<String,String> request){
        String select = request.get("selectText");
        String input = request.get("inputText");
        List<AftersalesLog> list = alsi.selectSelective(select,input);
        return list;
    }

    @RequestMapping("/deleteaftersale")
    public String deleteAfterSale(HttpServletRequest request){
        int i = Integer.parseInt(request.getParameter("aftersalesId"));
        alsi.deleteByPrimaryKey(i);
        return null;
    }


}
